package com.zhongjianjian.elasticjob.web;

import com.alibaba.fastjson.JSON;
import com.zhongjianjian.elasticjob.entity.UserEntity;
import com.zhongjianjian.elasticjob.utils.DateUtil;
import com.zhongjianjian.elasticjob.utils.FuZaiJiSuan;
import com.zhongjianjian.elasticjob.utils.UID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/2/25 08:42
 * 描述: 接收用户的订阅请求
 */

@RestController
public class JIeShouDataController {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    /**
     * 接收用户的订阅请求
     * @return
     */
    @RequestMapping("getDingYue")
    public boolean getDataOfDingYue(@RequestBody Map<String,String> map) throws ParseException {

          //第一步 产生模拟用户
          UserEntity  userEntity=new UserEntity(UID.getUUID32());

          String redisKey = FuZaiJiSuan.getRedisKey(redisTemplate, "ZSET", "ZIZENG1", 4);

          //给用户发送领券通知的时间
          long start = DateUtil.tiqian(map.get("start"), 1);
          //将数据存入ZSET

          Boolean add = redisTemplate.opsForZSet().add(redisKey, JSON.toJSONString(userEntity), start);

          return add;
    }

}
